const mongoose = require('mongoose')
const Content = require('../../model/content')
const pagination = require('mongoose-sex-page');


module.exports = async (req, res) => {
    var { page, id } = req.params
    try {
        var data = await pagination(Content).find({ article: id,status:true }).populate({ path: 'author', select: 'username type' }).populate({
            path: 'child',match:{status:true},populate: [{ path: 'author', select: 'username type' }, { path: 'reply', select: 'username' }]
        }).page(page).size(7).exec()
    }
    catch (err) {
        return res.send({
            data: null,
            meta: {
                status: 400,
                msg: '请求失败'
            }
        })
    }
    res.send({
        data,
        meta: {
            status: 200,
            msg: '请求成功'
        }
    })
}
